package com.ibiaoke.goods.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.StringUtils;
import com.ibiaoke.goods.entity.Adjust;
import com.ibiaoke.goods.entity.AdjustExample;
import com.ibiaoke.goods.mapper.AdjustMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;

@Repository
public class AdjustDao extends BaseDao<Adjust, AdjustExample, Integer, AdjustMapper> {

    @Autowired
    private AdjustMapper adjustMapper;

    @Override
    public AdjustMapper getMapper() {
        return adjustMapper;
    }

    public List<Adjust> findAdjustList(String goodName, Integer goodStockId, Integer goodId,Date adjustTime,Date adjustEndTime,String outName,
                                       String inName, Integer shopId,Page page){

        AdjustExample example = new AdjustExample();
        AdjustExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(goodName)) {
            criteria.andGoodNameLike("%" + goodName + "%");
        }

        if (goodId != null) {
            criteria.andGoodIdEqualTo(goodId);
        }

        if (goodStockId != null) {
            criteria.andIdEqualTo(goodStockId);
        }

        if (adjustTime != null) {
            criteria.andAdjustTimeGreaterThanOrEqualTo(adjustTime);
        }

        if(adjustEndTime != null){
            criteria.andAdjustTimeLessThanOrEqualTo(adjustEndTime);
        }

        if (StringUtils.isNotEmpty(outName)) {
            criteria.andOutShopNameLike("%" + outName + "%");
        }

        if (StringUtils.isNotEmpty(inName)) {
            criteria.andInShopNameLike("%" + inName + "%");
        }

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }

        page.setTotalCount(adjustMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        example.setOrderByClause("create_time desc");
        return selectByExample(example);



    }





}
